namespace TrueCode.DependencyManager.BuildActions.Lifetime
{
  public sealed class Singleton : ISingleton
  {
    private object _instance;


    public Singleton() : this( null )
    {
    }

    public Singleton( object instance )
    {
      _instance = instance;
    }

    public void Execute( IBuildSession context )
    {
      if( _instance != null )
        context.Instance = _instance;
      else
      {
        context.ExecuteNextBuildAction();
        _instance = context.Instance;
      }
    }
  }
}